home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr49
/
actlib13.zip
/
STRINGS.ZIP
/
STRNCPYB.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-02-25
|
1KB
|
47 lines
/* Copyright (C) 1993 Marc Stern (internet: stern@mble.philips.be) */
#include "strings.h"
#include <stdlib.h>
/***
* Function : strncpyb
*
* Description : Like strncpy but truncates trailing blanks and \n,
* skip leading blanks and adds a '\0'.
*
* Decisions :
*
* Parameters : out char * target
* in char * source
* in int length
*
* Return code : like strncpy
*
* Side-effects: Pad target string to length with '\0'.
*
* OS/Compiler : All
***/
char *strncpyb( char *target, const char *source, int length )
{ char *lastnonblank = target - 1, *ptr;
int offs = 0;
while ( *source++ == ' ' ) offs++; source--;
length -= offs;
for ( ptr = target; (length > 0) && *source; length-- )
{
if ( *source != ' ' && *source != '\n' )
lastnonblank = ptr;
*ptr++ = *source++;
}
memset( lastnonblank + 1, '\0', ptr - lastnonblank + length + offs );
return target;
}